package io.kblog.domain

import org.springframework.http.HttpStatus
import org.springframework.web.context.request.RequestContextHolder
import org.springframework.web.context.request.ServletRequestAttributes

open class ResponseBean() {
    var result: Any? = null
    var message: String? = "success"
    var status: Int = HttpStatus.OK.value()
        set(value) {
            (RequestContextHolder.getRequestAttributes() as ServletRequestAttributes?)?.response?.status = value
            field = value
        }
    val msg: String?
        get() = message
    val code: Int
        get() = status

    constructor(result: Any?, message: String, status: Int) : this() {
        this.result = result
        this.message = message
        this.status = status
    }

    constructor(result: Any?, message: String, status: HttpStatus) : this() {
        this.result = result
        this.message = message
        this.status = status.value()
    }

    constructor(result: Any?, message: String) : this() {
        this.result = result
        this.message = message
    }

    constructor(result: Any?) : this() {
        this.result = result
    }
}